package indi.kider.server.apartment.util;

import com.google.common.base.Strings;
import indi.kider.common.constant.HouseStateCons;
import indi.kider.common.constant.SetLeaseCons;
import indi.kider.common.model.apartment.Houses;
import indi.kider.server.apartment.model.HouseRent;
import indi.kider.server.apartment.model.HousesCommunityVO;

public class BuildModel
{
    public static HouseRent buildHouseRents(HousesCommunityVO vo) {
        HouseRent houseRent = vo.getHouseRent();
        StringBuilder sb = new StringBuilder();
        String area = vo.getHArea();//面积
        if (area != null)
            sb.append(area).append("m²·");
        String heading = vo.getHHeading();//朝向
        if (!Strings.isNullOrEmpty(heading))
            sb.append(heading).append("·");
        Integer cnt1 = vo.getHCnt1();//几室
        if (cnt1 != null) sb.append(cnt1).append("室·");
        Integer cnt2 = vo.getHCnt2();//几厅
        if (cnt2 != null) sb.append(cnt2).append("厅·");
        String desc = sb.toString();
        if (desc.length() > 0)
            desc = desc.substring(0, desc.lastIndexOf("·"));
        houseRent.setHouseDecs(desc);
        houseRent.setStateName(HouseStateCons.STATE_NAME_MAP.get(houseRent.getState()));
        if (vo.getRent() != null && vo.getRent().getId() != null)
            houseRent.setRent(vo.getRent());
        return houseRent;
    }

    public static HouseRent buildHouseRentsByHouse(Houses houses) {
        HouseRent houseRent = new HouseRent();
        houseRent.setHouseId(houses.getId());
        houseRent.setHouseNumb(houses.getHouseNumb());
        StringBuilder sb = new StringBuilder();
        if (houses.getArea() != null){ //面积
            sb.append(houses.getArea().toString()).append("m²·");
        }
        String heading = houses.getHeading();//朝向
        if (!Strings.isNullOrEmpty(heading))
            sb.append(heading).append("·");
        Integer cnt1 = houses.getCnt1();//几室
        if (cnt1 != null) sb.append(cnt1).append("室·");
        Integer cnt2 = houses.getCnt2();//几厅
        if (cnt2 != null) sb.append(cnt2).append("厅·");
        String desc = sb.toString();
        if (desc.length() > 0)
            desc = desc.substring(0, desc.lastIndexOf("·"));
        houseRent.setHouseDecs(desc);
        houseRent.setState(houses.getState());
        houseRent.setStateName(HouseStateCons.STATE_NAME_MAP.get(HouseStateCons.VACANCY));
        houseRent.setDeposit(houses.getDeposit());
        return houseRent;
    }
}
